﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Code;
using System.Data;


namespace E2_WEBSITE.Code.HDD
{
    public class HDDDataAccess
    {
        DataProvider m_DataProvider = DataProvider.GlobalDataProvider;
        public List<string> GetListMemoryByManufactureName(string sManufacture)
        {
            List<string> lstMemory = new List<string>();
            string sSql = "select distinct DUNGLUONG from HDD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "' AND SAN_PHAM.id=HDD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstMemory.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstMemory;
        }

        public List<string> GetListStandardByManufactureAndMemory(string sManufacture, string sMemory)
        {
            List<string> lstStandard = new List<string>();
            string sSql = "select distinct CHUAN from HDD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "'AND DUNGLUONG ='" + sMemory +"' AND SAN_PHAM.id=HDD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstStandard.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstStandard;
        }

        public List<string> GetListRoundByManufactureAndMemoryAndStandard(string sManufacture,string sMemory,string sStandard)
        {
            List<string> lstRound = new List<string>();
            string sSql = "select distinct SOVONG from HDD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "'AND DUNGLUONG ='" + sMemory + "' AND CHUAN='"+ sStandard + "' AND SAN_PHAM.id=HDD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstRound.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstRound;
        }

        public List<string> GetListProductByManuAndMemoryAndStandardAndRound(string sManufacture ,string sMemory,string sStandard, string sRound)
        {
            List<string> lstPro = new List<string>();
            string sSql = "select distinct TENSANPHAM from HDD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "'AND DUNGLUONG ='" + sMemory + "' AND CHUAN='" + sStandard + "'AND SOVONG='" + sRound +"' AND SAN_PHAM.id=HDD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstPro.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstPro;
        }

        public int GetHDDID(string sManufacture,string sMemory,string sStandard,string sRound,string sName)
        {
            int iID = -1;
           
            string sSql = "select SAN_PHAM.ID from HDD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "'AND DUNGLUONG ='" + sMemory + "' AND CHUAN='" + sStandard + "'AND SOVONG='" + sRound + "' AND TENSANPHAM ='" + sName + "' AND SAN_PHAM.id=HDD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                iID = int.Parse(dt.Rows[0][0].ToString());
            }
            return iID;
        }

    }
}
